<!--合约风险提示-->
<template>
  <div class="bg bg2">
    <div class="all acenter"  v-if="content">
      <div class="height80"></div>
      <text class="text28 text3 textSize">{{T('亲爱的用户')+'：'}}</text>

      <div class="height60"></div>
      <text class="text28 text3 textSize">{{T('为了确保您明确的认知并能更好的控制投资风险，您需要了解以下内容')}}</text>


      <div class="height60"></div>
      <text class="text28 text1 textSize">{{content}}</text>
      <div class="all"></div>

      <!--最后一页按钮-->
      <div :class="['but-ok', (time > 0 ? 'no1' : 'main1')]" v-if="tag == contents.length - 1" @click="opClick">
        <text class="font32 text1">{{T('接受并开通跟单') + (time > 0 ? ('('+time+')') : '')}}</text>
      </div>

      <!--第一页按钮-->
      <div :class="['but-ok', (time > 0 ? 'no1' : 'main1')]" v-else-if="tag == 0" @click="okClick">
        <text class="font32 text1">{{T('知道了') + (time > 0 ? ('('+time+')') : '')}}</text>
      </div>
      
      <!--中间页按钮-->
      <div class="buts" v-else>

        <div class="buts-back" @click="backClick">
          <text class="font32 text3">{{T('上一步')}}</text>
        </div>

        <div class="all"></div>
        <div :class="['buts-ok', (time > 0 ? 'no1' : 'main1')]" @click="okClick">
          <text class="font32 text1">{{T('知道了') + (time > 0 ? ('('+time+')') : '')}}</text>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

//功能
import navigator from "@/_js/navigator";
import modal from '@/_js/modal';
import math from '@/_js/math';
import broadcast from '@/_js/broadcast';
import API from '@/_js/api';
import amStrategy2 from "@/strategy/amStrategy2";

const globalEvent = weex.requireModule('globalEvent');
const weexFunction = weex.requireModule("WeexFunction");
import weexHttp from "@/_js/https"; ;

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T("开通合约策略交易"));

export default {

  data() {
    return {
      T:T,

      time:3,
      contents:[],
      content:undefined,
      tag:0,
    };
  },

  mounted() {

    var param = navigator.getParam('param');
    if (param) {
      this.contents = param.contents;
      this.tag = param.tag;
      this.initData();
    } else {
      setTimeout(() => {
        this.httpOpenFollowStrategy();
      }, 200);
    }
  },

  methods: {

    initData() {
      this.startTime();
      var content = this.contents[this.tag];
      this.content = this.tag + 1 + '、'+ content.content;
    },

    /********************************** http*/
    //http开启合约问题
    httpOpenFollowStrategy(){

      modal.showLoad();
      var param = {};
      weexHttp.post("contract/queryContractProblems",param,true,(data)=>{
        modal.hideLoad();
        if(data.status == 200){
          this.contents = data.data;
          this.initData();
        } else {
          modal.toast(data.msg);
        }
      });
    },

    //开通合约
    httpOpenContract () {

      modal.showLoad();
      var param = {};
      weexHttp.post("contract/confirmOpenContract",param,true,(data)=>{
        modal.hideLoad();
        if(data.status == 200){
          navigator.back(this.contents.length);

        } else {
          modal.toast(data.msg);
        }
      });
    },
    
    /********************************** 其他方法*/
    //开始计时
    startTime() {

      setTimeout(() => {
        this.time--;
        if (this.time > 0) {
          this.startTime();
        }
      }, 1000);
    },

    /********************************** Get*/
    getButStyle() {
      return
    },

    /********************************** 点击触发*/
    //知道了
    okClick() {
      if (this.time){
        return;
      }
      var param = {param:{'contents':this.contents, 'tag':this.tag+1}};
      navigator.open('', 'upContract/COp', param);
    },

    //上一步
    backClick() {
      navigator.back();
    },

    //开通
    opClick() {
      this.httpOpenContract();
    }
  }
};

</script>


<style src="@/_css/style.css"></style>
<style scoped>
.bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}
.textSize {
  width: 590px;
  line-height: 48px;
}
.but-ok{
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 670px;
  height: 80px;
  border-radius: 8px;

  margin-bottom: 70px;
}
.buts {
  flex-direction: row;
  width: 590px;
  height: 80px;

  margin-bottom: 70px;
}
.buts-back {
  flex-direction: row;
  align-items: center;
  width: 670px;
  height: 80px;
}
.buts-ok{
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 420px;
  height: 80px;
  border-radius: 8px;
}


.height60 {
  height: 60px;
}
.height80 {
  height: 80px;
}
</style>
